package demoMod.nanaki.patches.events.exordium;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.cards.curses.Normality;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractEvent;
import com.megacrit.cardcrawl.events.exordium.BigFish;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.characters.NanakiCharacter;

public class BigFishPatch {
    public static final String ID = NanakiMod.makeID("Big Fish");
    private static final EventStrings eventStrings;
    public static final String NAME;
    public static final String[] DESCRIPTIONS;
    public static final String[] OPTIONS;

    @SpirePatch(
            clz = BigFish.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static void Postfix(BigFish event) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                event.imageEventText.updateDialogOption(3, OPTIONS[4], new Normality());
            }
        }
    }

    @SpirePatch(
            clz = BigFish.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(BigFish event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                try {
                    Enum screen = ReflectionHacks.getPrivate(event, BigFish.class, "screen");
                    switch (screen.name()) {
                        case "INTRO":
                            switch (buttonPressed) {
                                case 0:
                                case 1:
                                case 2:
                                    return SpireReturn.Continue();
                                case 3:
                                    event.imageEventText.updateBodyText(DESCRIPTIONS[1] + DESCRIPTIONS[2] + DESCRIPTIONS[3]);
                                    AbstractRelic r = AbstractDungeon.returnRandomScreenlessRelic(AbstractDungeon.returnRandomRelicTier());
                                    AbstractDungeon.getCurrRoom().spawnRelicAndObtain((float) Settings.WIDTH / 2.0F, (float)Settings.HEIGHT / 2.0F, r);
                                    r = AbstractDungeon.returnRandomScreenlessRelic(AbstractDungeon.returnRandomRelicTier());
                                    AbstractDungeon.getCurrRoom().spawnRelicAndObtain((float) Settings.WIDTH / 2.0F, (float)Settings.HEIGHT / 2.0F, r);
                                    AbstractEvent.logMetricObtainCardAndRelic("Big Fish", "Box", new Normality(), r);
                                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new Normality(), (float)(Settings.WIDTH / 2), (float)(Settings.HEIGHT / 2)));
                                    break;
                            }
                            ReflectionHacks.setPrivate(event, BigFish.class, "screen", Enum.valueOf((Class<Enum>) Class.forName("com.megacrit.cardcrawl.events.exordium.BigFish$CurScreen"), "RESULT"));
                            event.imageEventText.clearAllDialogs();
                            event.imageEventText.setDialogOption(OPTIONS[5]);
                            return SpireReturn.Return(null);
                    }
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
            return SpireReturn.Continue();
        }
    }

    static {
        eventStrings = CardCrawlGame.languagePack.getEventString(ID);
        NAME = eventStrings.NAME;
        DESCRIPTIONS = eventStrings.DESCRIPTIONS;
        OPTIONS = eventStrings.OPTIONS;
    }
}
